package io.renren.modules.project.controller;

import io.renren.common.annotation.SysLog;
import io.renren.common.utils.R;
import io.renren.modules.project.service.ProjectAuthachService;
import io.renren.modules.project.vo.AuthachVoEntity;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

/**
 * 满意度统计表
 *
 * @author ygg
 * @date 2021-07-18 15:04:00
 */
@RestController
@RequestMapping("project/chartsurvey")
public class ChartSurveyController {

    @Autowired
    private ProjectAuthachService projectAuthachService;

    /**
     * 列表
     */
    @RequestMapping("/volist")
    public R volist(@RequestParam Map<String, Object> params){
        List<AuthachVoEntity> list = projectAuthachService.getAuthVoList(params);

        return R.ok().put("list", list);
    }

    /**
     * 导出控制点 Word文件
     * @param params
     * @return
     */
    @SysLog("导出满意统计表")
    @RequestMapping("/exportExcel")
    public void exportExcel(HttpServletResponse response,@RequestParam Map<String, Object> params) {
        try {
            HSSFWorkbook workbook = projectAuthachService.exportExcel(params);
            //准备将Excel的输出流通过response输出到页面下载
            response.setContentType("application/vnd.ms-excel");
            //设置导出Excel的名称
            response.setHeader("Content-disposition", "attachment;filename=" + params.get("title") + ".xls");
            //刷新缓冲
            response.flushBuffer();
            //workbook将Excel写入到response的输出流中，供页面下载该Excel文件
            workbook.write(response.getOutputStream());
            //关闭workbook
            workbook.close();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}
